package com.example.action;

import com.example.bean.Cart;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet( "/removeCart")
public class RemoveCartServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取要删除的商品的id
        //获取购物车
        //回到购物车页面
        int pid = Integer.parseInt(request.getParameter("pid"));
        Cart cart = (Cart)request.getSession().getAttribute("cart");
        cart.removeProdFromCart(pid);
        request.setAttribute("box", cart);
        request.getRequestDispatcher("shop-cart.jsp").forward(request, response);
    }
}
